import { getPackageJson, resolvePcgPath, getBasePlugins } from './utils.js'
import generatePackageJson from 'rollup-plugin-generate-package-json'
// 获取react包的输出路径
const distReactPath = resolvePcgPath('React', true)
const reactPath = resolvePcgPath('React')
const { name } = getPackageJson('React')

export default [
  // react
  {
    input: `${reactPath}/index.ts`,
    output: {
      file: `${distReactPath}/index.js`,
      name: 'index.js',
      format: 'umd', //及支持commonjs也支持es6模块化'
    },
    plugins: [
      ...getBasePlugins(),
      generatePackageJson({
        inputFolder: reactPath,
        outputFolder: distReactPath,
        baseContents: ({ name, description, version, author }) => ({
          name,
          description,
          version,
          author,
          main: 'index.js',
        }),
      }),
    ],
  },
  // dev-runtime
  {
    input: `${reactPath}/src/jsx.ts`,
    output: {
      file: `${distReactPath}/jsx-dev-runtime.js`,
      name: 'jsx-dev-runtime.js',
      format: 'umd', //及支持commonjs也支持es6模块化'
    },
    plugins: [
      ...getBasePlugins(),
      generatePackageJson({
        inputFolder: reactPath,
        outputFolder: distReactPath,
        baseContents: ({ name, description, version, author }) => ({
          name,
          description,
          version,
          author,
          main: 'index.js',
        }),
      }),
    ],
  },
  // react-runtime
  {
    input: `${reactPath}/src/jsx.ts`,
    output: {
      file: `${distReactPath}/jsx-runtime.js`,
      name: 'jsx-runtime.js',
      format: 'umd', //及支持commonjs也支持es6模块化'
    },
    plugins: [
      ...getBasePlugins(),
      generatePackageJson({
        inputFolder: reactPath,
        outputFolder: distReactPath,
        baseContents: ({ name, description, version, author }) => ({
          name,
          description,
          version,
          author,
          main: 'index.js',
        }),
      }),
    ],
  },
]
